<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #main {
        width: 500px;
        height: 500px;
      }
    </style>
  </head>

  <body>
    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM
    <div id="main" style="width: 600px;height:400px;"></div>

    <script src="./lib/echarts.min.js"></script>

    <script>
        const arr = [
            { name: "西兰花", price: 150 },
            { name: "西瓜", price: 230 },
            { name: "西葫芦", price: 224 },
            { name: "西北风", price: 34 },
            { name: "西红柿", price: 135 },
            { name: "土豆", price: 147 },
            { name: "秋刀鱼", price: 260 },
        ]
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        // 指定图表的配置项和数据

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption({
            title: {
                text: '前端36期全国第一嘎嘎牛逼',
                textStyle: {
                    color: " #107"
                }
            },
            legend: {  // 图例组件
                data: ['销量']  // 图例的数据数组,对应series里的name
            },
            tooltip: {},
            xAxis: {
                data: arr.map(item => item.name)
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'line',
                data: arr.map(item => item.price)
            }]
        });
    </script> -->

    <!-- //准备一个具备大小（宽高）的容器 -->
    <div id="main"></div>

    <script src="/lib/echarts.min.js"></script>

    <script>
      var chartDom = document.getElementById('main')
      var myChart = echarts.init(chartDom)
      var option

      const arr = [
        { name: '西兰花', price: 150 },
        { name: '西瓜', price: 230 },
        { name: '西葫芦', price: 224 },
        { name: '西北风', price: 34 },
        { name: '西红柿', price: 135 },
        { name: '土豆', price: 147 },
        { name: '秋刀鱼', price: 260 },
      ]

      const dataName =[]
      const dataPrice =[]

      arr.map(item =>{
        dataName.push(item.name)
        dataPrice.push(item.price)
      })
      option = {
        xAxis: {
          type: 'category',
          data: dataName,
        },
        yAxis: {
          type: 'value',
        },
        series: [
          {
            data: dataPrice,
            type: 'line',
          },
        ],
      }

      option && myChart.setOption(option)
    </script>
  </body>
</html>
